import sys
import os
import time
import math
BASE_PATH = os.path.dirname(
    os.path.dirname(os.path.abspath(__file__))
)
sys.path.insert(0,BASE_PATH)

from bin import get_Webdriver


class HistoryData_Search:
    def __init__(self):
        self.driver = get_Webdriver.Get_Webdriver().driver

    def jumptoHistoryDataSearchpage(self):
        """进入历史数据查询"""
        # self.driver.click("link_text=>数据查询")
        self.driver.click("link_text=>历史数据查询")

    def clickDataSearchpage(self):
        """点击资讯数据标签页"""
        self.driver.click("link_text=>资讯数据")

    def datapageClickmedia(self, mid):
        """资讯数据页面媒体类型"""
        self.driver.click("css=>input[value='{}'][name='filter_media']".format(mid))

    def clickAbordSearchpage(self):
        """点击境外数据标签页"""
        self.driver.click("link_text=>境外数据")

    def abordpageClickmedia(self, mid):
        """资讯数据页面，媒体类型
        mid -1全部 f facebook t twitter 3 境外新闻网站
        """
        self.driver.click("css=>input[name='filter_type'][value='{}']".format(mid))

    def clickAccountSearchpage(self):
        """点击账号数据标签页
        正式环境帐号的帐为“账”
        """
        self.driver.click("link_text=>账号数据")
        # self.driver.click("link_text=>帐号数据")

    def clickCompanySearchpage(self):
        """点击企业数据标签页"""
        self.driver.click("link_text=>企业数据")

    def clickCommentSearchpage(self):
        """点击电商和资讯评论数据标签页"""
        self.driver.click("link_text=>电商和资讯评论数据")

    def typeCommentMission(self, mname=''):
        """输入评论任务名称"""
        self.driver.clear("css=>#commentname")
        self.driver.type("css=>#commentname", mname)

    def clickCommentsearchButton(self):
        """输入评论任务名称"""
        self.driver.click("css=>#ctlBtn")

    def clickCommentUpdateType(self, value='1', addr=''):
        """选择上传方式1为本地上传，2为手动输入
        addr上传文件的路径或手动输入的url
        """
        if value == '1':
            self.driver.click("css=>input[the-id='toggleselection'][value='1']")
            self.driver.type("css=>.webuploader-element-invisible", addr)
        else:
            self.driver.click("css=>input[the-id='toggleselection'][value='2']")
            self.driver.clear("css=>#urls")
            self.driver.type("css=>#urls", addr)

    # def typeCommentManuladdr(self, urls=''):
    #     """手动输入url"""
    #     self.driver.clear("css=>#urls")
    #     self.driver.type("css=>#urls", urls)

    def typeDiffKeywords(self, keywords=''):
        """输入关键词"""
        self.driver.clear("css=>#keywords")
        self.driver.type("css=>#keywords", keywords)

    def clickExcludeWord(self):
        """点击添加排除词"""
        self.driver.click("css=>button[the-id='exclusion_word']")

    def getStatusOfExclude(self):
        """获取排除词输入框状态"""
        estyle = self.driver.get_attribute("css=>div[the-id='exclude']", 'style')
        return estyle

    def typeExcludeWord(self, exwords):
        """输入排除词"""
        self.driver.clear("css=>#exclude")
        self.driver.type("css=>#exclude", exwords)

    def clickTimerange(self, trange):
        """选择时间范围"""
        self.driver.click("css=>#date{}".format(trange))

    def typeStartTime(self, stime):
        """时间范围自定义，输入开始时间"""
        self.driver.clear("css=>#starttime")
        self.driver.type("css=>#starttime", stime)

    def typeEndTime(self, etime):
        """时间范围自定义，输入开始时间"""
        self.driver.clear("css=>#endtime")
        self.driver.type("css=>#endtime", etime)

    def typeMaxCount(self, mcount):
        """时间范围自定义，输入开始时间"""
        self.driver.clear("css=>#max_count")
        self.driver.type("css=>#max_count", mcount)

    def clickKeywordsearch(self):
        """点击关键词查询"""
        self.driver.click("css=>#query1")

    def typeKeywords(self, w1='', w2='', w3=''):
        """输入关键词"""
        self.driver.clear("css=>#w1")
        self.driver.type("css=>#w1", w1)
        self.driver.clear("css=>#w2")
        self.driver.type("css=>#w2", w2)
        self.driver.clear("css=>#w3")
        self.driver.type("css=>#w3", w3)

    def clickFunctionsearch(self):
        """点击表达式查询"""
        self.driver.click("css=>#query2")

    def typeFunctionwords(self, user_logic='', amb_w_logic=''):
        """输入关键词"""
        self.driver.clear("css=>#user_logic")
        self.driver.type("css=>#user_logic", user_logic)
        self.driver.clear("css=>#amb_w_logic")
        self.driver.type("css=>#amb_w_logic", amb_w_logic)

    def resultShowType(self, stype, addr=''):
        """选择数据输出类型
        stype = online excel sqlite json zmq
        """
        if stype == 'zmq':
            self.driver.click("css=>input[value='zmq']")
            self.driver.clear("css=>#zmqInput")
            self.driver.type("css=>#zmqInput", addr)
        else:
            self.driver.click("css=>input[value='{}://']".format(stype))


    def clickSearchButton(self):
        """点击提交查询按钮"""
        self.driver.click("css=>#search")

    def clickAccountDatapage(self):
        """点击账号数据标签页"""
        self.driver.click("link_text=>账号数据")

    def clickCompanyDatapage(self):
        """点击账号数据标签页"""
        self.driver.click("link_text=>账号数据")

    def clickBusinessDatapage(self):
        """点击电商和资讯评论数据标签页"""
        self.driver.click("link_text=>电商和资讯评论数据")

    def clickAbordDatapage(self):
        """点击电商和资讯评论数据标签页"""
        self.driver.click("link_text=>境外数据")


if __name__ == '__main__':
    pass